<!DOCTYPE html>
<html lang="en">
<head>
    <meta charset="UTF-8">
    <meta http-equiv="X-UA-Compatible" content="IE=edge">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <title>条件渲染 - 广告</title>
</head>
<body>
    <div id="root"></div>

    <script src="../js/react.development.js"></script>
    <script src="../js/react-dom.development.js"></script>
    <script src="../js/babel.min.js"></script>

    <script type="text/babel">
        //数据  标识是否是 vip 用户
        let isVip = false;

        //控制广告的显示
        function showAd(){
            if(isVip){
                return null;
            }else{
                return <img src="https://img2.baidu.com/it/u=1600846971,850068331&fm=253&fmt=auto&app=138&f=JPEG?w=1024&h=307"/>
            }
        }

        //1. 创建虚拟 DOM
        let vDOM = <div>
            {/*1. 逻辑与*/}
            {!isVip && <img src="https://img2.baidu.com/it/u=1600846971,850068331&fm=253&fmt=auto&app=138&f=JPEG?w=1024&h=307"/>}

            {/*2. 三元运算符*/}
            {isVip ? null : <img src="https://img2.baidu.com/it/u=1600846971,850068331&fm=253&fmt=auto&app=138&f=JPEG?w=1024&h=307"/> }

            {/*3. 函数调用*/}
            {showAd()}
        </div>

        //2. 渲染
        ReactDOM.render(vDOM, document.querySelector("#root"));
    </script>
</body>
</html>